package com.atguigu.mock.entity;

import com.atguigu.common.base.entity.AutoIdBase;
import com.atguigu.common.comment.Comment;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Entity
@Getter
@Setter
@NoArgsConstructor
@Comment("授信申请表")
public class CreditFacility extends AutoIdBase {
    @Comment(value = "申请人")
    @ManyToOne(optional = false)
    private BusinessPartner businessPartner;

    @OneToOne
    @Comment(value = "关联批复")
    private Reply reply;

    @Comment("关联授信")
    @OneToOne
    private Credit credit;

    @ManyToOne(optional = false)
    @Comment(value = "业务员")
    private Employee salesman;

    @Comment("所属行业")
    @ManyToOne
    private Industry industry;
    @Comment("业务方向")
    private String leaseOrganization;
    @Comment(value = "申请授信金额")
    private BigDecimal creditAmount;
    @Comment("所处环节：1.新建 2.未达到风控 3.待分配 4.已分配信审经办 5.信审经办审核通过 6.信审经办审核复议 7.业务反馈已提交 8.一级评审通过 9.一级评审复议 10.二级评审通过 11.二级评审复议 12.项目评审会审核通过 13.项目评审会复议 14.总经理/分管总审核通过 15.总经理/分管总审核复议 16.出具批复审核通过 17.出具批复审核复议 18 不满批复金额 19.新增授信 20.拒绝 21.取消")
    private Integer status;

    @OneToMany(mappedBy = "creditFacility", fetch = FetchType.EAGER)
    @OrderBy("updateTime")
    private List<CreditFacilityStatus> statusList;

    public void setStatusList(List<CreditFacilityStatus> statusList) {
        for (CreditFacilityStatus creditFacilityStatus : statusList) {
            creditFacilityStatus.setCreditFacility(this);
        }
        this.statusList = statusList;
    }

    public CreditFacility(LocalDateTime createTime, BusinessPartner businessPartner, Employee salesman, Industry industry, String leaseOrganization, BigDecimal creditAmount) {
        super(createTime);
        this.businessPartner = businessPartner;
        this.salesman = salesman;
        this.industry = industry;
        this.leaseOrganization = leaseOrganization;
        this.creditAmount = creditAmount;
    }
}
